package com.contrller;

import com.bean.RbacManager;
import com.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/myfirst")
public class MyFirstContrller  {

    @Autowired
    ManagerService managerService;

    @RequestMapping("/findlist")
    public String findlist(Model model,HttpServletRequest req,HttpServletResponse resp){
        List<Map<String, String>> findlist = managerService.findlist();
        model.addAttribute("msg",findlist);
        return "json返回页面的字符串";
    }

    @RequestMapping("/findbyname")
    public String findbyname(Model model,@RequestParam("name") String username){
        System.out.println("findbyname方法执行");
        List<Map<String, String>> findbyname = managerService.findbyname(username);
         model.addAttribute("msg",findbyname);
         return "success";
    }

    @RequestMapping(value = "/addForMap")
    public String addOneForMap(Map<String,Object> userinfo,Model model){
        System.out.println(userinfo);
        if (userinfo.size()!=0) {
            int i = managerService.addForMap(userinfo);
        }
        model.addAttribute("msg",userinfo);
        return "success";
    }

    @RequestMapping("/addOne")
    public String addOne(RbacManager rbacManager, Model model){
        int i = managerService.addOne(rbacManager);
        model.addAttribute("data","新增用户："+rbacManager);
        return "success";
    }
}
